package com.gitee.wsl.common.ui.draw.container

import androidx.compose.ui.geometry.Size
import com.gitee.wsl.common.ui.draw.api.Resizable
import com.gitee.wsl.common.ui.draw.api.ResizableSupport

class HeadlessContainer(
    override val density: Double = 1.0,
    private val resizableSupport: ResizableSupport = ResizableSupport()
): Container,
    Resizable by resizableSupport{

    override var size: Size = Size(100.0f, 100.0f)
        set(value) {
            field = value
            vizList.forEach {
                it.size = value
            }
            resizableSupport.notifyNewSize(value)
        }

    private val _vizList = mutableListOf<Viz>()

    override val vizList: List<Viz>
        get() = _vizList

    override fun newViz(init: Viz.() -> Unit): Viz {
        val viz = Viz().also {
            it.size = size
            it.init()
        }
        _vizList.add(viz)
        return viz
    }

}